<template>
	<view class="container">
		<u-navbar title="详情" is-fixed
			background="url('https://www.yplm888.com//uploads/20220803/7ed305f9a93ba50b049a7725662b18cc.png') no-repeat">
		</u-navbar>
		<video v-if="a" class="video-wrap" id="myVideo" :src="videoInfo.video_file" @stop='videoStop' @pause="videoPause"
			@timeupdate='videoTime' @play="videoPlay" @error="videoErrorCallback" :poster='videoInfo.cover_image'
			:initial-time='starTime' controls enable-play-gesture>
			
		</video>
		
		<template v-if="!a">
			<view>
				<player-component :vid="videoInfo.vid"></player-component>
			</view>
		</template>
		<!-- <image class="cover-image" src="https://www.yplm888.com/uploads/20220906/0c1f061c7f049a3167065baf9544fbbf.jpg" mode="scaleToFill"></image> -->
		<!-- <view v-if="isnotVideoPlaying" class="cover">
			<image class="cover-image" :src='pageType=="broandStory"?videoInfo.cover_image:videoInfo.cover_image' mode="scaleToFill"></image>
		</view> -->
		<view class="detail">
			
			<view class="">
				<text class="name">{{videoInfo.name}}</text>
			</view>

			<view class="secend-line">
				<u-icon class='icon' name="eye"></u-icon><text
					style="margin-right: 30rpx;">{{videoInfo.reading_volume}}</text>
				<u-icon class='icon' name="calendar"></u-icon>
				<text>{{videoInfo.createtime}}</text>
				<!-- <u-icon class='icon' name="clock"></u-icon><text></text> -->
			</view>
			<view class="play-button" v-if="videoInfo.type==2" @click="toAudioDetail">
				<u-icon name="play-circle-fill" color="#fe466b" size="30" ></u-icon>
				<view class="text">
					播放音频
				</view>
			</view>
			<view class="right" @click="changeCollect" v-if="pageType!='jiayouzhan'">
				<u-icon v-if="!isCollect" name="star" color='#ccc' size="40"></u-icon>
				<u-icon v-else name="star-fill" color='#FE5477' size="40"></u-icon>
			</view>
		</view>
		<scroll-view scroll-y="true" v-if="videoInfo.content" :style="'height:' + scrollH+'rpx;'">
			<view class="content-text">
				<view class="font-style-xie">大纲</view>
				<u-parse style='margin: 20rpx 0;' :html="videoInfo.outline_content"></u-parse>
				<view class="font-style-xie">详情</view>
				<u-parse :html="videoInfo.content"></u-parse>
			</view>
		</scroll-view>
		<!-- 更多视频 -->
		<view class="model" v-if="videoInfo.otherLst">
			<view class="font-style-xie">更多<text class="video-num">数量：{{videoInfo.otherLst.length}}</text></view>
			<scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll">
				<view class="show-item" v-for="(item, index) in videoInfo.otherLst" :key="item.id">
					<view class="image" @click="toPlay(item)">
						<image class="image" :src="item.cover_image" mode=""></image>
					</view>
				</view>
			</scroll-view>
		</view>
		<u-modal v-model="messageShow" :content="pageFilter(pageType)" @confirm='messageConfirm' show-cancel-button></u-modal>
	</view>
</template>

<script>
	import {
		mp3PlayMixin
	} from '@/mixin/mp3Play.js'
	import {
		requestSubscribeMessage
	} from '@/mixin/RSMessage.js'
	
	export default {
		mixins: [mp3PlayMixin, requestSubscribeMessage],
		data() {
			return {
				a:false,
				messageShow:false,
				videoInfo: '',
				baseUrl: this.$u.http.config.baseUrl,
				starTime: 0, //指定视频初始播放位置
				// duration: 0, //指定视频时长
				title: "", // 频的标题，全屏时在顶部展示
				poster: '', //视频封面的图片网络资源地址
				content: '',
				isCollect: false,
				old: {
					scrollTop: 0
				},
				audioUrl: '',
				detailInfo: {
					title: '',
					cover_image: ''
				},
				pageType: "",
				id: '',
				playTime: 0,
				isnotVideoPlaying: true,
				scrollH:0
			}
		},
		onLoad(option) {
			console.log(656, option)
			uni.setNavigationBarTitle({
				title: option.title
			})
			if(option.pageType == 'jiayouzhan')
			{
				this.a=true
			}
			this.pageType = option.pageType
			this.id = option.id
			this.initData(option.id)

		},
		onUnload() {
			this.addPlayOrder()
		},
		onReady() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					that.scrollH = res.windowHeight * 750 / res.windowWidth;
					// #ifdef MP-WEIXIN
					that.scrollH = res.windowHeight * 750 / res.windowWidth - parseInt(res.safeArea.top) - 750;
					// #endif
				}
			});
		},
		methods: {
			pageFilter(val){
				let page = {
					case: '经典案例',
					shore: '经验分享',
					lecture: '主题讲座',
					"liveBack": '直播回放', 
					'teamLeader':'组长团队', 
					'broandStory': '品牌故事', 
					'class':'课程', 
					'leader':'组长团队', 
					'Journa':'新闻咨询',
				}
				return '是否订阅'+page[val]+'上新通知?'
			},
			async messageConfirm(){
				let res = await this.getStatus()
				this.RSMessage(res)
			},
			toAudioDetail() {
				if (this.videoInfo.type == 1) return
				this.$u.route('/packageB/pages/hostpotDetail/hostpotDetail', {
					id: this.videoInfo.id,
					title: this.videoInfo.title,
					pageType: this.pageType
				})
			},
			toPlay(data){
				if(data.type == 0){
					this.$u.route('/packageB/pages/hostpotDetail/hostpotDetail', {
						id: data.id,
						title: data.name,
						pageType: this.pageType
					})
				}else{
					this.initData(data.id)
				}
				
			},
			initData(id) {
				let type = {
					liveBack: 'getLivebackInfo',
					broandStory: 'BrandstoryInfo',
					jiayouzhan: 'CultivateDetail'
				}
				let quaryType = type[this.pageType]
				console.log(quaryType)
				this.$u.api[quaryType]({
					id
				}).then(res => {
					this.videoInfo = res.data
					this.isCollect = res.data.is_collection
					if (res.data.is_subscribe == 0) {
						this.messageShow = true
					}
				})
			},
			// 记录播放时间
			addPlayOrder() {
				console.log(this.pageType)
				if(this.playTime==0)return
				let typeList = ['junshi', 'case', 'share', 'lecture', "liveBack", 'teamLeader', 'broandStory', 'class', 'leader', 'Journa', 'jiayouzhan']
				let typeNum = typeList.indexOf(this.pageType) + 1
				let data = {
					curriculum_id: this.id,
					second: this.playTime,
					curriculum_type: typeNum,
					product_id: this.videoInfo.id
				}
				this.$u.api.ProductRecord(data).then()
			},
			videoPlay() {
				this.isnotVideoPlaying = false
			},
			videoPause(e) {
				this.addPlayOrder()
			},
			videostop(e) {
				this.addPlayOrder()
			},
			videoTime(e) {
				this.playTime = e.detail.currentTime
			},
			videoErrorCallback: function(e) {
				uni.showModal({
					content: e.target.errMsg,
					showCancel: false
				})
			},
			scroll: function(e) {
				console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			},
			// 收藏
			changeCollect() {
				let typeList = ['junshi', 'case', 'share', 'lecture', "liveBack", 'teamLeader', 'broandStory', 'class', 'leader', 'Journa', 'jiayouzhan']
				let type = typeList.indexOf(this.pageType)
			
				this.$u.api.collect({
					collection_id: this.videoInfo.id,
					collection_type: type + 1
				}).then(res => {
					if (res.code == 1) {
						this.isCollect = !this.isCollect
						uni.showToast({
							title: res.msg
						})
					}
				})
			},

		}
	}
</script>



<style lang="scss">
	.container {
		position: relative;
		width: 100%;
		.cover {
			width: 100%;
			.cover-image {
				width: 100%;
				height: 400rpx;
				z-index: 66;
				position: absolute;
				top: 185rpx;
				right: 0;
			}
		}
		.cover-image {
			width: 100%;
			height: 400rpx;
			z-index: 66;
			position: absolute;
			top: 185rpx;
			right: 0;
		}
	}

	.video-wrap {
		text-align: center;
		width: 100%;
		height: 400rpx;
		background-color: #000000;
	}

	.detail {
		padding: 0 20rpx;
		margin: 0 20rpx;
		margin-top: 20rpx;
		border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
		position: relative;

		.name {
			font-size: 36rpx;
			margin-left: 10rpx;
			font-weight: 700;
			width: 90%;
		}

		.secend-line {
			color: #ccc;
			margin-left: 10rpx;
			padding-bottom: 10rpx;

			.icon {
				margin-right: 20rpx;
			}

		}
		
		.play-button{
			color: #FE5477;
			position: absolute;
			width: 150rpx;
			align-items: center;
			display: flex;
			flex-direction: column;
			bottom: 15rpx;
			right: 60rpx;
			.text{
				font-size: 20rpx;
			}
		}

		.right {
			position: absolute;
			bottom: 20rpx;
			right: 20rpx;
		}
	}

	.content-text {
		margin-top: 10rpx;
		margin: 30rpx;
		padding-bottom: 20rpx;
	}

	.font-style-xie {
		font-weight: 700;
		font-size: 32rpx !important;
		font-style: italic;

		.video-num {
			font-style: normal;
			font-weight: normal;
			font-size: 16rpx;
			color: #FE5477;
			float: right;
			margin-right: 10rpx;
			margin-top: 10rpx;
		}
	}

	.model {
		height: 300rpx;
		margin-top: 40rpx;
		padding: 0 40rpx;

		.scroll-view_H {
			margin-top: 20rpx;
			white-space: nowrap;
			width: 100%;

			.show-item {
				display: inline-block;

				.image {
					height: 150rpx;
					width: 200rpx;
					border-radius: 20rpx;
					margin-right: 20rpx;
					background-color: #ccc;

					.image {
						height: 150rpx;
						width: 200rpx;
						border-radius: 20rpx;
					}
				}
			}
		}
	}
</style>
